package org.yang.snake.controller;

import org.yang.snake.model.SysRole;
import org.yang.snake.service.SysRoleService;
import org.yang.snake.util.Result;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.security.access.prepost.PreAuthorize;

import javax.annotation.Resource;

/**
 * 角色(SysRole)表控制层
 *
 * @author shichenyang
 * @since 2019-08-21 11:05:13
 */
@Controller
@RequestMapping("sysRole")
public class SysRoleController {
   /**
     * 服务对象
     */
    @Resource
    private SysRoleService sysRoleService;

    @PreAuthorize("hasAuthority('sysRole')")
    @GetMapping("/index")
    public String index(){
        return "sysRole/index";
    }
    
    @PreAuthorize("hasAuthority('sysRole_add')")
    @GetMapping("/add")
    public String add(){
        return "sysRole/add";
    }

    @PreAuthorize("hasAuthority('sysRole_update')")
    @GetMapping("/update")
    public String update(){
        return "sysRole/update";
    }
    
    @PreAuthorize("hasAuthority('sysRole')")
    @GetMapping("/list")
    @ResponseBody
    public Result list(SysRole sysRole,Integer page,Integer limit){
        return sysRoleService.listAll(sysRole,page,limit);
    }
    
    @PreAuthorize("hasAuthority('sysRole_add')")
    @PostMapping("/add")
    @ResponseBody
    public Result add(SysRole sysRole){
        return sysRoleService.insert(sysRole);
    }
    
    @PreAuthorize("hasAuthority('sysRole_update')")
    @PostMapping("/update")
    @ResponseBody
    public Result update(SysRole sysRole){
        return sysRoleService.update(sysRole);
    }

    @PreAuthorize("hasAuthority('sysRole_delete')")
    @PostMapping("/delete")
    @ResponseBody
    public Result delete(Long id){
        return sysRoleService.deleteById(id);
    }
}